<template>
	<view class="body">

		<!-- 操作菜单 -->
		<view class="paper-left-popup-mask" v-show="show" @tap="hidepopup"></view>
		<view class="paper-left-popup" v-show="show">
			<view class="uni-flex" hover-class="paper-left-popup-h" @tap="addfriend">
				<view class="icon iconfont icon-sousuo"></view>加好友
			</view>
			<view class="uni-flex" hover-class="paper-left-popup-h" @tap="clear">
				<view class="icon iconfont icon-qingchu"></view>清除缓存
			</view>
		</view>
		<!-- 小纸条列表 -->
		<block v-for="(item,index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		<!-- 上拉加载 -->
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
	import paperList from "../../components/paper/paper-list.vue";
	import loadMore from "../../components/common/load-more.vue";
	export default {
		components: {
			loadMore,
			paperList
		},
		data() {
			return {
				show:false,
				loadtext: "上拉加载更多",
				list: [{
						userpic: "../../static/demo/userpic/7.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "0"
					},
					{
						userpic: "../../static/demo/userpic/8.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "8"
					},
					{
						userpic: "../../static/demo/userpic/9.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "0"
					},
					{
						userpic: "../../static/demo/userpic/10.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "1"
					},
					{
						userpic: "../../static/demo/userpic/11.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "5"
					},
					{
						userpic: "../../static/demo/userpic/12.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "13"
					},
					{
						userpic: "../../static/demo/userpic/6.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "0"
					},
					{
						userpic: "../../static/demo/userpic/5.jpg",
						username: "帅宝",
						time: "10:21",
						data: "我是信息，今天晚上吃饭",
						noreadnum: "13"
					}
				]
			}
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.getdata()
		},
		onReachBottom() {
			this.loadmore()
		},
		// 监听导航栏点击事件
		onNavigationBarButtonTap(e) {
				switch (e.index){
					case 0:
						uni.navigateTo({
							url: '../user-list/user-list',
						});
						this.hidepopup();
						break;
					case 1:
						this.showpopup();
						break;
					
				}
			
		},
		methods: {
			// 获取数据
			getdata() {
				setTimeout(() => {
					// 获取模拟数据
					let arr = [{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "xxl",
							time: "10:21",
							data: "我是信息，今天晚上吃饭",
							noreadnum: "0"
						},
						{
							userpic: "../../static/demo/userpic/2.jpg",
							username: "xxl",
							time: "12:21",
							data: "我是信息，今天晚上吃饭",
							noreadnum: "18"
						}
					];
					// 赋值
					this.list = arr;
					// 关闭
					uni.stopPullDownRefresh();

				}, 1000);
			},
			// 上拉加载
			loadmore() {
				if (this.loadtext != "上拉加载更多") {
					return;
				}
				// 修改状态（加载状态）
				this.loadtext = "加载中...."
				// 获取数据
				setTimeout(() => {
					// 获取完成状态
					// 一条模拟数据
					let obj = {
						userpic: "../../static/demo/userpic/2.jpg",
						username: "哇哦",
						time: "8:21",
						data: "哇哦，时间到了，该吃早饭了",
						noreadnum: "2"
					};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				}, 1000);
				// this.loadtext="到底了"
			},
			// 操作事件
			addfriend(){
				console.log('加糗友')
				this.hidepopup();
			},
			clear(){
				console.log("清除缓存")
				this.hidepopup();
			},
			hidepopup(){
				this.show=false;
			},
			showpopup(){
				this.show=true;
			}

		}
	}
</script>

<style>
	.uni-flex {
		display: flex;
		justify-content: flex-start;
	}

	.flex-sp {
		display: flex;
		justify-content: space-between;
		align-content: space-between;
	}

	.body {
		padding: 0 2%;
	}
	.paper-left-popup-mask{
		position: fixed;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
		z-index: 1999;
	}

	.paper-left-popup {
		position: fixed;
		right: 0;
		background: #FFFFFF;
		z-index: 2000;
		width: 45%;
		box-shadow: 1upx 1upx 20upx 2upx #CCCCCC;
	}

	.paper-left-popup>view {
		padding: 15upx;
		font-size: 30upx;
	}

	.paper-left-popup>view>view {
		margin-right: 10upx;
		font-weight: 600;
	}
	.paper-left-popup-h{
		background: #EEEEEE;
	}
</style>
